#include "DeviceIni.h"

DeviceIni::DeviceIni()
{
}

bool DeviceIni::parser()
{
    if(!this->check())
    {
        return false;
    }

    QSettings settings(m_path, QSettings::IniFormat);
    settings.setIniCodec("UTF-8");
    qDebug()<<"open ini";
    int deviceNum = settings.value("device.num_i").toInt();

    for(int i=0; i<deviceNum; i++)
    {
        ElevatorStruct Struct;
        if(settings.value("device." + QString::number(i,10) + ".posInZoneEn").toString().contains("Household"))
        {
        Struct.m_IP=settings.value("device." + QString::number(i,10) + ".ip_ip").toString();
        QString roomData=settings.value("device." + QString::number(i,10) + ".zone").toString().right(4);
	QString zoneData=settings.value("device." + QString::number(i,10) + ".zone").toString();
        Struct.m_roomnum=roomData.toULong(0,16);
	 Struct.m_roomZone=zoneData;
          if(Struct.m_IP=="192.168.10.155")

      //  qDebug()<<i;
      //  qDebug()<<"ini IP="<<Struct.m_IP;
        qDebug()<<"ini Struct.m_roomZone="<<Struct.m_roomZone;
        StructMap.insert(Struct.m_IP,Struct);

        }
        if(settings.value("device." + QString::number(i,10) + ".posInZoneEn").toString().contains("Security Center1"))
        {
        Struct.m_center1IP=settings.value("device." + QString::number(i,10) + ".ip_ip").toString();
        StructMap.insert(Struct.m_center1IP,Struct);
        }
        if(settings.value("device." + QString::number(i,10) + ".posInZoneEn").toString().contains("Security Center2"))
        {
        Struct.m_center2IP=settings.value("device." + QString::number(i,10) + ".ip_ip").toString();
        StructMap.insert(Struct.m_center2IP,Struct);
        }
    }
return true;
}


QString DeviceIni::getZoneByIP(QString ip)
{
    if(!this->check())
    {
        return NULL;
    }
    QSettings settings(m_path, QSettings::IniFormat);
    settings.setIniCodec("UTF-8");
    qDebug()<<"open ini";
    int deviceNum = settings.value("device.num_i").toInt();
    for(int i=0; i<deviceNum; i++)
    {
       if(settings.value("device." + QString::number(i,10) + ".ip_ip").toString()==ip)
       {
           return settings.value("device." + QString::number(i,10) + ".zone").toString();
       }
    }
    return NULL;

}

void DeviceIni::clear()
{
    return;
}
